package com.newgd.blockchain.demo.task;

import com.alibaba.fastjson.JSONArray;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 获取交易数据的定时任务
 * Created by Niki on 2018/4/14 10:46
 */
@Component
public class TradesTask {
    /*创建处理查询数据的线程池，固定3个，依数据库处理速度调整线程池个数*/
    private static ExecutorService threadPool = Executors.newFixedThreadPool(3);


    /**
     * 每15分钟运行一次
     */
    @Scheduled(cron = "0 0/15 * * * ?")
    public void tradesTask() {

        JSONArray data = TradesRequest.getTrades();
        //开线程往数据库中插入查询的数据
        threadPool.execute(new TradesExecute(data));
    }
}
